package com.touchportfolio.view
{
	import com.touchportfolio.model.ApplicationModel;
	import com.touchportfolio.model.utils.EffectsUtilities;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;

	public class InfoBalk extends InfoBalkBasic
	{
		private var _appModel:ApplicationModel = ApplicationModel.getInstance();
		private var _stage:Stage;
		
		private var _buttonBorder1:Sprite;
		private var _buttonBorder2:Sprite;
		
		public function InfoBalk()
		{
			_stage = _appModel.stage;
			_stage.addEventListener(Event.RESIZE, onStageResize);
			_appModel.addEventListener(ApplicationModel.COLOR_CHANGE, colorChange);

			_buttonBorder1 = new Sprite();
			_buttonBorder2 = new Sprite();
			_buttonBorder1.graphics.lineStyle(1, 0);
			_buttonBorder1.graphics.lineTo(0, this.height);
			_buttonBorder2.graphics.lineStyle(1, 0);
			_buttonBorder2.graphics.lineTo(0, this.height);
			this.leftBtn.addChild(_buttonBorder1);
			this.leftBtn.addChild(_buttonBorder2);
			this.setChildIndex(leftBtn, this.numChildren-1);
			
			onStageResize(null);

			colorChange();
			
		}
		
		private function colorChange(e:Event = null):void{
			EffectsUtilities.setSpriteToColor(this.leftBtn.balk, ApplicationModel.getInstance().color, 1);
			EffectsUtilities.setSpriteToColor(this.rightBtn.balk, ApplicationModel.getInstance().color, 1);
			EffectsUtilities.setSpriteToColor(this.balk_info, ApplicationModel.getInstance().color, 1);
		}
		
		private function onStageResize(e:Event):void
		{
			this.balk_info.width = _stage.stageWidth/2;
			this.leftBtn.x = _stage.stageWidth/2;
			this.leftBtn.balk.width = _stage.stageWidth*.25 + 1 ;
			this.leftBtn.btnBg.width = _stage.stageWidth*.25 + 1;
			this.buttonMode = true;
			this.leftBtn.addEventListener(MouseEvent.CLICK, onLeftClickHandler);

			this.rightBtn.x = _stage.stageWidth*.75 + 1;
			this.rightBtn.balk.width = _stage.stageWidth*.25;
			this.rightBtn.btnBg.width = _stage.stageWidth*.25;
			this.rightBtn.arrowRight.x = this.rightBtn.width - this.rightBtn.arrowRight.width - 15;
			this.buttonMode = true;
			this.rightBtn.addEventListener(MouseEvent.CLICK, onRightClickHandler);
			
			_buttonBorder2.x = _stage.stageWidth*.25;
		}
		
		private function onLeftClickHandler(e:MouseEvent):void
		{
			_appModel.activeImage--;
		}
		
		private function onRightClickHandler(e:MouseEvent):void
		{
			_appModel.activeImage++;
		}
	}
}